<?php defined('_JEXEC') or die('Restricted access'); ?>
<script language="JavaScript">
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery('form#adminForm select#username').change(function () {
	var str = "";
	str = jQuery(this).val();
	jQuery.ajax({
			type: "POST",
			data: "username=" + str,
			url: "index.php?option=com_congregation&controller=profile&task=name&format=raw",
			success: function(msg){
				if (msg){
					jQuery("form#adminForm input#fname").val(msg.fname);
					jQuery("form#adminForm input#lname").val(msg.lname);
				}
				else
				{
					jQuery("form#adminForm input#name").val('');
				}
			},
			dataType: 'json'
		});
          
		  
		  
	});
});

</script>

<form action="index.php"  enctype="multipart/form-data" method="post" name="adminForm" id="adminForm">
<div class="col100">
	<fieldset class="adminform">
		<legend><?php echo JText::_( 'Details' ); ?></legend>

		<table class="admintable">
		<tr>
			<td valign="top"  align="right" class="key">
				<?php echo JText::_('Photo:' ); ?>
			</td>
			<td valign="top">
				<input type='file' name='photo' />
				<br />
				
				<?php 
				if(!empty($this->profile->photo)):  
					echo "<img src='" . JURI::root(). 'media/congregation/profiles/thumbnails/' .  $this->profile->photo->filename . "'/>"; 
					echo "<br /><input type='checkbox' name='remove_photo' value='1' /> " . JText::_("Remove photo");
				endif;
				?>
			</td>
 		<tr>		
		<tr>
		
			<td width="100" align="right" class="key">
				<label for="username">
					<?php echo JText::_( 'Username' ); ?>:
				</label>
			</td>
			<td>
			<?php if($this->profile->username): ?>
			<input type='hidden' name='username' value="<?php echo $this->profile->username ?>" />
			<?php echo $this->profile->username ?>
			<?php else: ?>
			<select name='username' id='username' class='inputbox' size='1'>
			<option value=''><?php echo JText::_( 'Select a username' ) ?></option>
			<?php foreach($this->freeusers as $freeuser): ?>
			<option value='<?php echo $freeuser->username ?>'><?php echo $freeuser->username?></option>
			<?php endforeach; ?>
			</select>
			<?php endif; ?>
			</td>
		</tr>
		
		<tr>
			<td width="100" align="right" class="key">
				<label for="lname">
					<?php echo JText::_( 'Lastname' ); ?>:
				</label>
			</td>
			<td>
				<input name='lname' id='lname' class='inputbox' value="<?php echo $this->profile->lname ?>" />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="fname">
					<?php echo JText::_( 'Firstname' ); ?>:
				</label>
			</td>
			<td>
				<input name='fname' id='fname' class='inputbox' value="<?php echo $this->profile->fname ?>" />
			</td>
		</tr>
		
<?php

	$b_label[0] = JText::_('Birth');
	$b_label[1] = JText::_('Entrance');
	$b_label[2] = JText::_('Novitiate');
	$b_label[3] = JText::_('First Profession');
	$b_label[4] = JText::_('Final Vows');
	$b_label[5] = JText::_('Ordination');
	$b_label[6] = JText::_('Death');

	$b_day[0] = substr($this->profile->bdate, 8, 2);
	$b_month[0] = substr($this->profile->bdate, 5, 2);
	$b_year[0] = substr($this->profile->bdate, 0, 4);
	$b_place[0] = $this->profile->bplace;

	$b_day[1] = substr($this->profile->edate, 8, 2);
	$b_month[1] = substr($this->profile->edate, 5, 2);
	$b_year[1] = substr($this->profile->edate, 0, 4);
	$b_place[1] = $this->profile->eplace;

	$b_day[2] = substr($this->profile->ndate, 8, 2);
	$b_month[2] = substr($this->profile->ndate, 5, 2);
	$b_year[2] = substr($this->profile->ndate, 0, 4);
	$b_place[2] = $this->profile->nplace;

	$b_day[3] = substr($this->profile->vdate, 8, 2);
	$b_month[3] = substr($this->profile->vdate, 5, 2);
	$b_year[3] = substr($this->profile->vdate, 0, 4);
	$b_place[3] = $this->profile->vplace;

	$b_day[4] = substr($this->profile->fdate, 8, 2);
	$b_month[4] = substr($this->profile->fdate, 5, 2);
	$b_year[4] = substr($this->profile->fdate, 0, 4);
	$b_place[4] = $this->profile->fplace;

	$b_day[5] = substr($this->profile->odate, 8, 2);
	$b_month[5] = substr($this->profile->odate, 5, 2);
	$b_year[5] = substr($this->profile->odate, 0, 4);
	$b_place[5] = $this->profile->oplace;
	
	$b_day[6] = substr($this->profile->ddate, 8, 2);
	$b_month[6] = substr($this->profile->ddate, 5, 2);
	$b_year[6] = substr($this->profile->ddate, 0, 4);
	$b_place[6] = $this->profile->dplace;

?>
<? for($m=0; $m<=6; $m++): ?>
  <tr>
  <td align="right" class="key">
   <label for='b_day[]'> <?php echo $b_label[$m] ?></label>
  </td>
  <td valign='top'>

<SELECT name='b_day[]'>
<OPTION selected><?php echo $b_day[$m] ?><option>1 <option>2 <option>3 <option>4 
<option>5 <option>6 <option>7 <option>8 <option>9 
<option>10
<option>11 <option>12 <option>13 <option>14 
<option>15 <option>16 <option>17 <option>18 
<option>19 <option>20 <option>21
<option>22 <option>23 <option>24 <option>24 
<option>25 <option>26 <option>27 <option>28 
<option>29 <option>30 <option>31
</SELECT>
<select name='b_month[]'>
<option value='<?php echo $b_month[$m] ?>' selected><?php echo $b_month[$m] ?></option>

<?php 
for ($i=1; $i<=12; $i++) {
	echo  "<option value='$i'>$i</option>";
}
?>

</select>
<select name='b_year[]'>
<option selected><?php echo $b_year[$m] ?></option>";
<?php 

$thisyear = date("Y");

for ($j = $thisyear - 200 ;$j <= $thisyear ; $j++) {
	echo  "<option value='$j'>$j</option>\n";
}
?>
</select> dd/mm/yyyy
 </td>
 </tr>
<tr>
  <td  align="right" class="key">
  <?php echo JText::_('Place of') . ' ' . $b_label[$m] ?>
  </td>
  <td valign='top'>
   <input type=text name='b_place[]' class='inputbox' value='<?php echo $b_place[$m] ?>' />
  </td>
 </tr>		
 <?php endfor; ?>
 		<tr>
			<td width="100" align="right" class="key">
				<label for="status">
					<?php echo JText::_( 'Status' ); ?>:
				</label>
			</td>
			<td>
			<select name='status' id='status' class='inputbox' size='1'>
			<option value=''><?php echo JText::_( 'Select a status' ) ?></option>
			<?php foreach($this->statuses as $status): ?>
				<option value='<?php echo $status->id ?>' <?php if($this->profile->status == $status->id) echo " selected='selected' " ?>><?php echo $status->text?></option>
			<?php endforeach; ?>
			</select>
			
			</td>
		</tr>
 		<tr>
			<td width="100" align="right" class="key">
				<label for="language">
					<?php echo JText::_( 'Language' ); ?>:
				</label>
			</td>
			<td>
			<select name='language' id='language' class='inputbox' size='1'>
			<option value=''><?php echo JText::_( 'Select a language' ) ?></option>
			<?php foreach($this->languages as $key => $language): ?>
				<option value='<?php echo $key ?>' <?php if($this->profile->language == $key) echo " selected='selected' " ?>><?php echo $language?></option>
			<?php endforeach; ?>
			</select>
			
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="nationality">
					<?php echo JText::_( 'Nationality' ); ?>:
				</label>
			</td>
			<td>
			<select name='nationality' id='nationality' class='inputbox' size='1'>
			<option><?php echo $this->profile->nationality ?></option>
<option>Italy<option>Afghanistan<option>Albania<option>Algeria<option>American Samoa<option>Andorra<option>Angola<option>Anguilla<option>Antarctica<option>Antigua and arbuda<option>Argentina<option>Armenia<option>Aruba<option>Australia<option>Austria<option>Azerbaijan<option>Bahamas<option>Bahrain<option>Bangladesh<option>Barbados<option>Belarus<option>Belgium<option>Belize<option>Benin<option>Bermuda<option>Bhutan<option>Bolivia<option>Bosnia and Herzegovina<option>Botswana<option>Bouvet Island<option>Brazil<option>British Indian Ocean Territory<option>Brunei Darussalam<option>Bulgaria<option>Burkina Faso<option>Burundi<option>Cambodia<option>Cameroon<option>Canada<option>Cape Verde<option>Cayman Islands<option>Central African Republic<option>Chad<option>Chile<option>China<option>Christmas Island<option>Cocos Keeling Islands<option>Colombia<option>Comoros<option>Congo<option>Cook Islands<option>Costa Rica<option>Ivory Coast<option>Croatia<option>Cuba<option>Cyprus<option>Czech Republic<option>Denmark<option>Djibouti<option>Dominican Republic<option>Dominica<option>East Timor<option>Ecuador<option>Egypt<option>El Salvador<option>Equatorial Guinea<option>Eritrea<option>Estonia<option>Ethiopia<option>Falkland Islands<option>Faroe Islands<option>Fiji<option>Finland<option>France<option>French Guiana<option>French Polynesia<option>French Southern Territories<option>Gabon<option>Gambia<option>Georgia<option>Germany<option>Ghana<option>Gibraltar<option>Greece<option>Greenland<option>Grenada<option>Guadeloupe<option>Guam<option>Guatemala<option>Guinea-Bissau<option>Guinea<option>Guyana<option>Haiti<option>Heard and McDonald Islands<option>Honduras<option>Hong Kong<option>Hungary<option>Iceland<option>India<option>Indonesia<option>Iran<option>Iraq<option>Ireland<option>Israel<option>Italy<option>Jamaica<option>Japan<option>Jordan<option>Kazakhstan<option>Kenya<option>Kiribati<option>North Korea<option>South Korea<option>Kuwait<option>Kyrgyzstan<option>Laos<option>Latvia<option>Lebanon<option>Lesotho<option>Liberia<option>Libya<option>Liechtenstein<option>Lithuania<option>Luxembourg<option>Macau<option>Macedonia<option>Madagascar<option>Malawi<option>Malaysia<option>Maldives<option>Mali<option>Malta<option>Marshall slands<option>Martinique<option>Mauritania<option>Mauritius<option>Mayotte<option>Mexico<option>Micronesia<option>Moldova<option>Monaco<option>Mongolia<option>Montserrat<option>Morocco<option>Mozambique<option>Myanmar<option>Namibia<option>Nauru<option>Nepal<option>Netherlands Antilles<option>Netherlands<option>New Caledonia<option>New Zealand<option>Nicaragua<option>Nigeria<option>Niger<option>Niue<option>Norfolk Island<option>Northern Mariana slands<option>Norway<option>Oman<option>Pakistan<option>Palau<option>Panama<option>Papua New Guinea<option>Paraguay<option>Peru<option>Philippines<option>Pitcairn<option>Poland<option>Portugal<option>Puerto Rico<option>Qatar<option>Reunion<option>Romania<option>Russian Federation<option>Rwanda<option>S Georgia and S Sandwich Isles<option>Saint Kitts and Nevis<option>Saint Lucia<option>Saint Vincent and The Grenadines<option>Samoa<option>San Marino<option>Sao Tome and Principe<option>Saudi Arabia<option>Senegal<option>Seychelles<option>Sierra Leone<option>Singapore<option>Slovak Republic<option>Slovenia<option>Solomon Islands<option>Somalia<option>South Africa<option>Spain<option>Sri Lanka<option>St. Helena<option>St. Pierre and Miquelon<option>Sudan<option>Suriname<option>Svalbard and Jan Mayen Islands<option>Swaziland<option>Sweden<option>Switzerland<option>Syria<option>Taiwan<option>Tajikistan<option>Tanzania<option>Thailand<option>Togo<option>Tokelau<option>Tonga<option>Trinidad and Tobago<option>Tunisia<option>Turkey<option>Turkmenistan<option>Turks and Caicos Islands<option>Tuvalu<option>US Minor Outlying Islands<option>Uganda<option>Ukraine<option>United Arab Emirates<option>United Kingdom<option>United States<option>Uruguay<option>Uzbekistan<option>Vanuatu<option>Vatican City State<option>Venezuela<option>Viet Nam<option>British Virgin Islands<option>US Virgin Islands<option>Wallis and Futuna Islands<option>Western Sahara<option>Yemen<option>Yugoslavia<option>Zaire<option>Zambia<option>Zimbabwe</select>

			</select>			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="cell">
					<?php echo JText::_( 'Telephon' ); ?>:
				</label>
			</td>
			<td>
			<input type='text' name='cell' id='cell' class='inputbox' value='<?php echo $this->profile->cell ?>' />
			</td>
		</tr>
		<tr>
			<td width="100" align="right" class="key">
				<label for="skype">
					<?php echo JText::_( 'Skype' ); ?>:
				</label>
			</td>
			<td>
			<input type='text' name='skype' id='skype' class='inputbox' value='<?php echo $this->profile->skype ?>' />
			</td>
		</tr>
	</table>
	</fieldset>
	
	<fieldset class="adminform">
	<legend><?php echo JText::_('Paths') ?></legend>
<p><?php echo JText::_('Please specify paths with date exact or at least the year') ?></p>



	<?php $house_list_option = '' ; //to get ?>
	<?php $last_p_id = 0 ?>
	<?php foreach($this->houses as $house): ?>
	<?php if($last_p_id != $house->p_id): ?>
	<?php $house_list_option .= "<option disabled=\"disabled\">" . $house->p_name . "</option>"; ?>
	<?php endif; ?>
	<?php $last_p_id = $house->p_id ?>
	<?php $house_list_option .= "<option value=\"" . $house->c_id . "\" >|__ " . $house->c_name . "</option>"; ?>
	<?php endforeach; ?>

	
	<?php 
	$day_list = "<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option><option>24</option><option>24</option><option>25</option><option>26</option><option>27</option><option>28</option><option>29</option><option>30</option><option>31</option>";
	$month_list = "<option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option>";
	$year_list = "";
	$thisyear = date("Y");

	for ($j = $thisyear; $j >= $thisyear - 100 ; $j--) {
		$year_list .= "<option value='$j'>$j</option>\n";
	}
	?>
			
<table width="100%" class="admintable">
<thead>
	<tr>
		<th class="key"><?php echo JText::_('Date') ?></th>
		<th><?php echo JText::_('Community') ?></th>
		<th><?php echo JText::_('Event or Responsibility') ?></th>
		<th><?php echo Jtext::_('Current') ?></th>
		<th><?php echo Jtext::_('Delete') ?></th>
	</tr>
</thead>
<tbody>
	<?php $i = 0 ; ?>
	<?php if(!empty($this->profile->paths)): ?>
	
	<?php foreach($this->profile->paths as $path) : ?>
	<tr>
		<td>
		<select name="path[<?php echo $i ?>][t_day]">
		<option><?php echo substr($path->t_date,8,2) ?></option>
		<?php echo $day_list ?>
		</select>
		<select name="path[<?php echo $i ?>][t_month]">
		<option><?php echo substr($path->t_date,5,2) ?></option>
		<?php echo $month_list ?>
		</select>
		<select name="path[<?php echo $i ?>][t_year]">
		<option><?php echo substr($path->t_date,0,4) ?></option>
		<?php echo $year_list ?>
		</select>
		</td>
		<td>
		<select name="path[<?php echo $i ?>][t_house]">
		<option value="<?php echo $path->t_cid ?>"><?php echo $path->c_name ?></option>
		<?php echo $house_list_option ?>
		</select>
		</td>
		<td>
		<input type='text' name="path[<?php echo $i ?>][t_charge]" value="<?php echo $path->t_charge ?>" />
		</td>
		<td>
		<input type='radio' name="t_current" value="<?php echo $i ?>" <?php if($path->t_current == 1) echo " checked='checked' " ?> />
		</td>
		<td>
		<input type='checkbox' name="path[<?php echo $i ?>][delete]" value="1" />
		</td>
	</tr>
	<?php $i++; endforeach; ?>
	<?php endif; ?>
	<?php for($j = $i; $j < $i + 5; $j++): ?>
	<tr>
		<td>
		<select name="path[<?php echo $j ?>][t_day]">
		<option></option>
		<?php echo $day_list ?>
		</select>
		<select name="path[<?php echo $j ?>][t_month]">
		<option></option>
		<?php echo $month_list ?>
		</select>
		<select name="path[<?php echo $j ?>][t_year]">
		<option></option>
		<?php echo $year_list ?>
		</select>
		
		</td>
		<td>
		<select name="path[<?php echo $j ?>][t_house]">
		<option></option>
		<?php echo $house_list_option ?>
		</select>
		</td>
		<td>
		<input type='text'  name="path[<?php echo $j ?>][t_charge]" value="" />
		</td>
		<td>
		<input type='radio' name="t_current" value="<?php echo $j ?>" />
		</td>
	</tr>
	
	<?php endfor; ?>
</tbody>
</table>
	
</div>
<div class="clr"></div>

<input type="hidden" name="option" value="com_congregation" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="id" value="<?php echo $this->profile->id ?>" />
<input type="hidden" name="controller" value="profile" />
</form>
